﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Treinamento2015_01.Controllers
{
    public class BaseController : Controller
    {
        //Controla a culture da sessão
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            if(Request == null)
                return base.BeginExecuteCore(callback, state);

            HttpCookie httpCookie = Request.Cookies["languageCulture"];

            CultureInfo c;
            if (httpCookie == null)
                c = new CultureInfo("en-US");
            else
                c = new CultureInfo(httpCookie.Value);

            System.Threading.Thread.CurrentThread.CurrentCulture = c; //datetime, ...
            System.Threading.Thread.CurrentThread.CurrentUICulture = c; //resources, ...

            return base.BeginExecuteCore(callback, state);
        }

    }
}